<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script src="/js/jquery.validation/1.14.0/messages_zh.min.js"></script>
</head>
<body>
<div class="container">
    <form id="addUserForm">
        <br/>
        <div class="form-group">
            <label for="paper_name">试卷名称：</label>
            <input type="hidden" value="${paper.paper_id}" id="paper_id">
            <input type="text" class="form-control" id="paper_name" name="paper_name" placeholder="输入名称" value="${paper.paper_name}">
        </div>
        <div class="form-group">
            <label for="ptype_id">试卷类型：</label>
            <select class="form-group" id="ptype_id">
                <option value="${paper.ptype.ptype_id}">${paper.ptype.ptype_name}</option>
            <#list ptypeList as ptype>
                <option value="${ptype.ptype_id}" class="form-group">${ptype.ptype_name}</option>
            </#list>
            </select>
        </div>
        <div class="form-group">
            <label for="dura">考试时间：</label>
            <input type="text" class="form-control" id="dura" name="dura" placeholder="请输入考试时间" value="${paper.dura}">
        </div>
        <div class="form-group">
            <label for="class_id">考试班级：</label>
            <select class="form-group" id="class_id">
                <option value="${paper.aClass.class_id}">${paper.aClass.class_name}</option>
            <#list classList as class>
                <option value="${class.class_id}" class="form-group">${class.class_name}</option>
            </#list>
            </select>
        </div>
        <div class="form-group">
            <label for="pwd">密令：</label>
            <input type="text" class="form-control" id="pwd" name="pwd" placeholder="是否更改考试成绩" value="${paper.p_key}">
            <input type="button" id="c_pwd" class="btn " value="重新生成密令">
        </div>
        <div class="form-group">
            <label for="pwd">满分：</label>
            <input type="text" class="form-control" id="full" name="full" placeholder="是否更改考试成绩" value="${paper.full}" readonly="true">
        </div>
        <div class="form-group">
            <label for="pwd">及格分数：</label>
            <input type="text" class="form-control" id="pass" name="pass" placeholder="是否更改考试成绩" value="${paper.pass}">
        </div>
        <div class="form-group">
            <button type="button" id="saveBtn" class="btn btn-success">提交</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
    </form>
</div>
<script>
    var editUser = function () {
        $.ajax({
            type:"GET",
            url:"/paper/editPaper.do",
            data:{
                "paper_id":parseInt($("#paper_id").val()),
                "paper_name":$("#paper_name").val(),
                "ptype.ptype_id":parseInt($("#ptype_id").val()),
                "dura":$("#dura").val(),
                "aClass.class_id":parseInt($("#class_id").val()),
                "p_key":$("#pwd").val(),
                "full":parseInt($("#full").val()),
                "pass":parseInt($("#pass").val())
            },
            dataType:"json",
            success:function () {
                yes();
            },
            error:function () {
            }
        })
    };
    $("#c_pwd").click(
            function () {
                $("#pwd").val(Math.floor(Math.random() * 1000000000));
            }
    );
    $("#cancelBtn").on("click",function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.getUserPageList();
        parent.layer.close(index);
        parent.layer.msg("操作取消",{icon: 5});
    });
    function yes(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.getUserPageList();
        parent.layer.close(index);
        parent.layer.msg("修改成功",{icon: 1});
    }
    $("#saveBtn").on("click",function () {
        editUser();
    });
</script>
</body>
</html>